package com.ss12.bustrack;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.os.Bundle;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.widget.Toast;

public class GestureInput extends Activity implements OnGesturePerformedListener, OnInitListener
{
	private GestureLibrary gLibrary;
/*
	private static final int ACTION_QUIT    = 0x00000001;
	private static final int ACTION_NEWDEST = 0x00000002;
	private static final int ACTION_NEARLOC = 0x00000003;
*/	
	/** Setup the GestureInput activity. */
	public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
		GestureOverlayView gOverlayView = new GestureOverlayView(this);
		android.view.View inflate = getLayoutInflater().inflate(R.layout.main, null);
		gOverlayView.addView(inflate);
		gOverlayView.addOnGesturePerformedListener(this);
		
		gLibrary = android.gesture.GestureLibraries.fromRawResource(this, R.raw.gestures);
		if (!gLibrary.load())
		{
			//startActivityForResult(new Intent(getApplicationContext(), 
								   //BusTrack.class), ACTION_QUIT);
			Toast.makeText(this, "Faild", Toast.LENGTH_SHORT).show();
		}
		setContentView(gOverlayView);
		//android.view.View.setContentView();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
    	super.onActivityResult(requestCode, resultCode, data);
    	switch (resultCode)
    	{
    		
    	} // End Switch
    }
	
	/** Capture the gesture and decide what the user is trying to do. */
	public void onGesturePerformed(GestureOverlayView gOverlayView, 
								   Gesture g)
	{
		ArrayList<android.gesture.Prediction> predictions = gLibrary.recognize(g);
		android.gesture.Prediction prediction;
		if (predictions.size() > 0)
		{
			prediction         = predictions.get(0);
			String pEntryName  = prediction.name;
			double pEntryScore = prediction.score;
		
			for (int i = 1; i < predictions.size(); i++)
			{
				prediction = predictions.get(i);
				if (prediction.score > pEntryScore)
				{
					pEntryScore = prediction.score;
					pEntryName  = prediction.name;
				}
			} // End FOR
			
			Toast.makeText(this, pEntryName, Toast.LENGTH_SHORT).show();
			
			/*
			if (pEntryName.equals("ToLeft"))
				startActivityForResult(new Intent(getApplicationContext(), GetLocation.class));
			else if (pEntryName.equals("ToRight"))
				startActivityForResult(new Intent(getApplicationContext(), AddNewLocation.class));
			else
				startActivityForResult(new Intent(getApplicationContext(), DestroyApp.class));
			*/
			
		} // End IF
		
	}

	public void onInit(int arg0) {
		// TODO Auto-generated method stub
		
	}
}
